package com.hongkuncheng.cms.freemaker.string;

import java.io.UnsupportedEncodingException;
import java.util.List;
import java.net.URLEncoder;

import org.springframework.stereotype.Component;
import freemarker.template.TemplateMethodModelEx;
import freemarker.template.TemplateModelException;

@Component
public class UrlEncodeMethod implements TemplateMethodModelEx {

    @Override
    public Object exec(List args) throws TemplateModelException {
        try {
            return URLEncoder.encode(args.get(0).toString(), "UTF-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
            return null;
        }
    }

}
